<?php
/*
Plugin Name: BuddyPress for WP e-Commerce
Version: 0.11
Requires at least: WP 3.0, BuddyPress 1.2.5
Tested up to: WP 3.0, BuddyPress 1.2.6
Author: Paul Gibbs
Author URI: http://byotos.com
Site Wide Only: true
Network: true
Domain Path: /includes/languages/
Text Domain: bpsc
*/

/* Only load the component if BuddyPress is loaded and initialized. */
function bpsc_init() {
	global $wpdb;

	require( dirname( __FILE__ ) . '/includes/bpsc-core.php' );

	// TODO: do install/upgrade properly.
	if ( !get_blog_option( BP_ROOT_BLOG, 'bpsc' ) ) {
		update_blog_option( BP_ROOT_BLOG, 'bpsc', array( 'is_installed' => true ) );

		// Country fields
		$country_codes = $wpdb->get_col( $wpdb->prepare( "SELECT country FROM " . WPSC_TABLE_CURRENCY_LIST . " ORDER BY country ASC" ) );
		$tikipress_fields = array();
		$tikipress_fields[] = array( 'type' => 'selectbox', 'name' => __( 'Billing Country', 'bpsc' ), 'description' => false, 'values' => $country_codes );
		// TODO1 $tikipress_fields[] = array( 'type' => 'selectbox', 'name' => __( 'Shipping Country', 'bpsc' ), 'description' => false, 'values' => $country_codes );

		$counter = 0;
		foreach ( $tikipress_fields as $field ) {
			$_POST['selectbox_option'] = $field['values'];

			$field_id = xprofile_insert_field( array( 'field_group_id' => 1, 'type' => $field['type'], 'name' => $field['name'], 'description' => $field['description'], 'is_required' => 0, 'can_delete' => 1, 'field_order' => $counter ) );
			$counter++;
		}

		// Add tikipress checkout fields
		//if ( !defined( 'WPSC_TICKETS_FOLDER' ) )
			return;

		if ( !$field_group_id = xprofile_insert_field_group( array( 'name' => __( 'TikiPress Fields', 'bpsc' ) ) ) )
			return;

		// Tikipress specific fields
		$tikipress_field_selectboxes = array();
		$tikipress_fields = array(
			array( 'type' => 'selectbox', 'name' => __( 'T-Shirt Size', 'bpsc' ), 'description' => false , 'values' => array( 'Mens Small', 'Mens Medium', 'Mens Large', 'Mens X Large', 'Womens Small', 'Womens Medium', 'Womens Large', 'Womens X Large' ) ),
			array( 'type' => 'selectbox', 'name' => __( 'Meal Restrictions', 'bpsc' ), 'description' => false, 'values' => array( 'none', 'Vegan', 'Vegetarian', 'Gluten Free' ) ),
			array( 'type' => 'selectbox', 'name' => __( 'How long have you been using WordPress', 'bpsc' ), 'description' => false, 'values' => array( 'never', 'less than 6 mnths', '6-12mnths', '1yr', '2yrs', '3yrs', '4yrs', '5yrs', '6yrs' ) ),
			array( 'type' => 'selectbox', 'name' => __( 'How many WordPress blogs do you manage', 'bpsc' ), 'description' => false, 'values' => array( 'none', '1 - 2', '3 - 5', '6 - 10', '11 - 20', '20 +' ) ),
			array( 'type' => 'selectbox', 'name' => __( 'Which sessions are you most likely to attend', 'bpsc' ), 'description' => false, 'values' => array( 'Blogger', 'BeginnerDev', 'AdvancedDev', 'CMS', 'Academic', 'BuddyPress', 'opensource' ) ),
			array( 'type' => 'selectbox', 'name' => __( 'How would you describe yourself', 'bpsc' ), 'description' => __( 'if more than one, choose the one that will influence your choice of sessions at this WordCamp', 'bpsc' ), 'values' => array( 'Personal Blogger', 'Corporate Blogger', 'Plugin Developer', 'Theme Developer', 'Theme Designer (no coding)', 'System Admin', 'Core Contributer', 'Forum Moderator', 'BuddyPress/MU', 'Open Source Community' ) ),
			array( 'type' => 'selectbox', 'name' => __( 'Do you make money from your WordPress Website', 'bpsc' ), 'description' => false, 'values' => array( 'None', 'Day Job', 'Support', 'Custom Development', 'Hosting', 'Ads', 'E-Commerce', 'Themes', 'Plugins' ) )
		);

		$counter = 0;
		foreach ( $tikipress_fields as $field ) {
			$_POST['selectbox_option'] = $field['values'];

			$field_id = xprofile_insert_field( array( 'field_group_id' => $field_group_id, 'type' => $field['type'], 'name' => $field['name'], 'description' => $field['description'], 'is_required' => 0, 'can_delete' => 1, 'field_order' => $counter ) );
			$counter++;
		}
	}
}
add_action( 'bp_init', 'bpsc_init' );
?>